package com.jiuzhou.guanwang.jzcp.presenter;

import com.google.gson.Gson;
import com.jiuzhou.guanwang.jzcp.URLConfig;
import com.jiuzhou.guanwang.jzcp.base.BasePresenter;
import com.jiuzhou.guanwang.jzcp.bean.NearlyLotteryResult;
import com.jiuzhou.guanwang.jzcp.netutil.NetRequestUtil;
import com.jiuzhou.guanwang.jzcp.view.LastOpenView;
import com.vise.log.ViseLog;

import org.xutils.common.Callback;

import java.util.HashMap;
import java.util.Map;

public class LastOpenPresenter extends BasePresenter<LastOpenView> {
    public LastOpenPresenter(LastOpenView view) {
        super.attachView(view);
    }


    public void getData(String name) {
        view.showLoadingDialog();
        Map<String, String> map = new HashMap<>();
        map.put("key", "220bb0a30d947");
        map.put("name", name);
        Callback.Cancelable post = NetRequestUtil.getInstance().get(URLConfig.OPENCODE_QUERY, map, 101,
                new NetRequestUtil.NetResponseListener<String>() {
                    @Override
                    public void onSuccess(String response, int requestCode) {
                        ViseLog.d(response);
                        NearlyLotteryResult result = (NearlyLotteryResult) new Gson().fromJson(response, NearlyLotteryResult.class);
                        view.onDataSuccess(result);
                    }

                    @Override
                    public void onFailed(String response, int requestCode) {
                        ViseLog.e("请求失败");
                        view.showToast("返回失败");
                    }

                    @Override
                    public void onError(Throwable e) {
                        view.showToast("返回解析异常");
                    }

                    @Override
                    public void onFinished() {
                        view.dismissLoadingDialog();
                    }
                });
    }
}